package com.infonam.media.adapters;

import java.util.List;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.infonam.media.R;
import com.infonam.media.data.VideoInfo;

public class VideoAdapter extends ArrayAdapter<VideoInfo> {

	private List<VideoInfo> videoFileList;
	private Context vContext;
	public VideoAdapter(Context context, int textViewResourceId,List<VideoInfo> videoFileList) {
		super(context, textViewResourceId, videoFileList);
		this.videoFileList = videoFileList;
		this.vContext = context;
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View row = convertView;
		  if(row==null){
		   LayoutInflater inflater=(LayoutInflater) vContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
		   row=inflater.inflate(R.layout.row, parent, false);
		  }
		 
		  TextView textfilePath = (TextView)row.findViewById(R.id.FilePath);
		  textfilePath.setText(videoFileList.get(position).getTitle());
		  ImageView imageThumbnail = (ImageView)row.findViewById(R.id.Thumbnail);
		 
//		  Bitmap bmThumbnail;
//		        bmThumbnail = ThumbnailUtils.createVideoThumbnail(videoFileList.get(position).getPath(), Thumbnails.MICRO_KIND);
		        imageThumbnail.setImageBitmap(videoFileList.get(position).getBmThumbnail());
		 
		  return row;
		 }
	
	@Override
	public void unregisterDataSetObserver(DataSetObserver observer) {
	    if (observer != null) {
	        super.unregisterDataSetObserver(observer);
	    }
	}
	}

